package com.oracle.malldemo.dao.impl;

import com.oracle.malldemo.dao.CatalogDao;
import com.oracle.malldemo.domain.Catalog;
import com.oracle.malldemo.util.DruidDBUtil;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class CatalogDaoImpl implements CatalogDao {

    @Override
    public List<Catalog> queryAllCatalog() {
        String sql = "select * from catalog";
        ResultSet rs = null;
        List<Catalog> catalogList = new ArrayList<Catalog>();
        try{
           rs = DruidDBUtil.executeQuery(sql,null);
           while(rs.next()){
               Catalog c = new Catalog();
               c.setCid(rs.getInt("cid"));
               c.setCatalog(rs.getString("catalog"));
               c.setPid(rs.getInt("pid"));
               catalogList.add(c);
           }
           return catalogList;
        }catch(Exception ex){
            ex.printStackTrace();
            return catalogList;
        }finally{
            DruidDBUtil.closeAll();
        }
    }
}
